using UnityEngine;

public class ButtonCar : MonoBehaviour
{
	[SerializeField]
	private UISprite sprite;

	[SerializeField]
	private string carDoor;

	[SerializeField]
	private string motoDoor;

	[SerializeField]
	private string tankDoor;

	[SerializeField]
	private string boatDoor;

	[SerializeField]
	private string helicopterDoor;

	private void Start()
	{
		if (sprite == null)
		{
			sprite = GetComponent<UISprite>();
		}
	}

	private void OnEnable()
	{
		if (GameController.instance.curTypeGame == TypeGame.race || GameController.instance.curTypeGame == TypeGame.tanks || GameController.instance.curTypeGame == TypeGame.RocketLeague || GameController.instance.curTypeGame == TypeGame.WalkingRobots)
		{
			base.gameObject.SetActive(false);
		}
		if (GameController.instance.curTypeGame == TypeGame.TitanfallV2 && PlayerBehavior.MyPlayer != null && PlayerBehavior.MyPlayer.currentCar != null && PlayerBehavior.MyPlayer.currentCar is TitanBehavior)
		{
			base.gameObject.SetActive(false);
		}
	}

	public void SetCarType(CarType types)
	{
		switch (types)
		{
		case CarType.Car:
			sprite.spriteName = carDoor;
			break;
		case CarType.Boat:
			sprite.spriteName = boatDoor;
			break;
		case CarType.Helicopter:
			sprite.spriteName = helicopterDoor;
			break;
		case CarType.Motorcycle:
			sprite.spriteName = motoDoor;
			break;
		case CarType.Tank:
			sprite.spriteName = tankDoor;
			break;
		}
	}

	private void OnPress(bool isDown)
	{
		if (!base.gameObject.activeSelf)
		{
			return;
		}
		if (GameController.instance.curScriptLestnica != null)
		{
			GameController.instance.curScriptLestnica.OnStair(false);
		}
		if (GameController.instance.playerScript.isShock || !isDown)
		{
			return;
		}
		if (!GameController.instance.playerScript.inCar && !GameController.instance.playerScript.inHelic)
		{
			GameController.instance.playerScript.GetInCar();
			if (PointerController.instance != null && PrivateCarManager.instance != null && PrivateCarManager.instance.currentCar != null)
			{
				PointerController.instance.RemovePointer(PrivateCarManager.instance.currentCar.transform);
			}
		}
		else if (!TutorialManager.TuturialWorking() && (GameController.instance.playerScript.inCar || GameController.instance.playerScript.inHelic))
		{
			GameController.instance.playerScript.GetOutOfCar(true);
		}
	}
}
